﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace IronSharePoint
{
    public class WebAppFeatureReceiver : SPFeatureReceiver
    {
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWebConfigModification config = new SPWebConfigModification();
            config.Path = "configuration/System.Workflow.ComponentModel.WorkflowCompiler/authorizedTypes";
            config.Name = "authorizedType[@Assembly='IronSharePoint'][@Namespace='IronSharePoint.Workflow.Activities'][@TypeName='*'][@Authorized='True']";
            config.Sequence = 0;
            config.Owner = "IronSharePoint";
            config.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
            config.Value = "<authorizedType Assembly='IronSharePoint, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ffb14d545e0a52c1' Namespace='IronSharePoint.Workflow.Activities' TypeName='*' Authorized='True' />";

            SPWebService service = SPWebService.ContentService;
            service.WebConfigModifications.Add(config);

            service.Update();
            service.ApplyWebConfigModifications();   
        }

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            
        }

        public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        {
            
        }

        public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        {
            
        }
    }
}
